﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Xml.Serialization;


namespace FATCASchema.Utilities
{
    public static class XMLDeserializer
    {

        public static T DeserializeObjectFromFile<T>(string formatsFilePath)
            where T : class
        {
            if (!File.Exists(formatsFilePath))
                return null;

            XmlSerializer deserializer = new System.Xml.Serialization.XmlSerializer(typeof(FATCA_OECD));            

            using (FileStream reader = new FileStream(formatsFilePath, FileMode.Open))
            {
                reader.Seek(0, SeekOrigin.Begin);

                return (T)(deserializer.Deserialize(reader));
            }
        }
    }
}
